﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArrayList练习
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //ArrayList arrayList = new ArrayList();
            //ArrayList arrayList2 = new ArrayList();

            ////int Add(object value)
            ////向集合中添加元素，返回元素在集合中的下标
            //arrayList.Add(1);
            //arrayList2.Add(2);
            //arrayList2.Add(3);
            //arrayList2.Add(2);

            ////获取指定下标的元素
            ////集合名[下标]
            //Console.WriteLine(arrayList[0]);


            ////void AddRange(ICollection c)
            ////向集合中添加另一个集合，这里是数组集合
            //arrayList.AddRange(arrayList2);
            ////ArrayList 为所有数组的基类，Array类实现了ICollection
            //arrayList.AddRange(new int[] { 5, 6 });
            //foreach (var i in arrayList)
            //{
            //    Console.Write(i + " ");
            //}
            //Console.WriteLine();

            ////bool Contains(object item)
            ////判断集合中是否含有item元素，有则返回True, 无则返回False
            //Console.WriteLine(arrayList.Contains(2));
            //Console.WriteLine(arrayList.Contains(4.0));

            ////void CopyTo(Array array)
            ////从目标数组 array 的第 0 个位置开始，将整个集合的元素复制到类型兼容的数组 array中
            //int[] ints2 = new int[20];
            //arrayList.CopyTo(ints2);
            //foreach (int i in ints2)
            //{
            //    Console.Write(i + " ");
            //}
            //Console.WriteLine();

            ////int IndexOf(object value)
            ////返回 value 在集合中第一次出现的位置
            //Console.WriteLine(arrayList.IndexOf(2));

            ////int LastIndexOf(object value)
            ////返回 value 在集合中最后一次出现的位置
            //Console.WriteLine(arrayList.LastIndexOf(2));

            ////void Insert(int index,object value)
            ////在集合的指定索引中插入元素
            //arrayList.Insert(2, 8);
            //foreach (var i in arrayList)
            //{
            //    Console.Write(i + " ");
            //}
            //Console.WriteLine();

            ////void Remove(object obj)
            ////将元素 value 从集合中移除
            //arrayList.Remove(8);
            //foreach (var i in arrayList)
            //{
            //    Console.Write(i + " ");
            //}
            //Console.WriteLine();

            ////void RemoveAt(int index)
            ////移除指定索引 index 的元素
            //arrayList.RemoveAt(0);
            //arrayList.Remove(8);
            //foreach (var i in arrayList)
            //{
            //    Console.Write(i + " ");
            //}
            //Console.WriteLine();

            ////void RemoveRange(int index,int count)
            ////移除指定位置 index 处开始往后的 count 元素
            //arrayList.RemoveRange(0, 2);
            //foreach (var i in arrayList)
            //{
            //    Console.Write(i + " ");
            //}
            //Console.WriteLine();

            ////void Reverse()
            ////将集合中的元素顺序反转
            //arrayList.Reverse();
            //foreach (var i in arrayList)
            //{
            //    Console.Write(i + " ");
            //}
            //Console.WriteLine();

            //arrayList.AddRange(new int[] { 18, 12, 14, 16, 9, 10 });

            ////将集合中的元素进行排序，默认为升序
            //arrayList.Sort();
            //foreach (var i in arrayList)
            //{
            //    Console.Write(i + " ");
            //}
            //Console.WriteLine();

            //ArrayList arrayList = new ArrayList();
            //ArrayList odd = new ArrayList();
            //ArrayList even = new ArrayList();
            //int[] ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            //foreach (int i in ints)
            //{
            //    if(i % 2 == 1)
            //    {
            //        odd.Add(i);
            //    }
            //    else
            //    {
            //        even.Add(i);
            //    }
            //}

            //arrayList.AddRange(odd);
            //arrayList.AddRange(even);
            //foreach(int i in arrayList)
            //{
            //    Console.Write(i + " ");
            //}
            //Console.WriteLine();


            ArrayList arrayList1 = new ArrayList(new string[] { "a", "b", "c", "e", "f", "g" });
            ArrayList arrayList2 = new ArrayList(new string[] { "e", "f", "g", "h", "i", "j", "k" });
            foreach(string item in arrayList2)
            {
                if(!arrayList1.Contains(item))
                {
                    arrayList1.Add(item);
                }
            }
            foreach (string item in arrayList1)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        
    }
}
